<?php
/*
 * Browser Detection class, by Olivier St-Laurent
 * 
 * Usage example : 
 *      echo Browser::getName() . " " . Browser::getVersion();
 */
class Browser{
    private static $name= null;
    private static $version= null;
    private static $detected= false;
    private static $browsers= array(
        
        "firefox",
        "msie",
        "opera",
        "chrome",
        "safari",
        
        "mozilla",
        "seamonkey",
        "konqueror",
        "netscape",
        "gecko",
        "navigator",
        "mosaic",
        "lynx",
        "amaya",
        "omniweb",
        "avant",
        "camino",
        "flock",
        "aol",
        
        );
    
    private static function detect(){
        if (Browser::$detected) return;
        $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
        foreach(Browser::$browsers as $browser){
            if(preg_match('#('.$browser.')[/ ]?([0-9.]*)#', $agent, $match)){
                Browser::$name = $match[1];
                Browser::$version = $match[2];
                break;
            }
        }
        Browser::$detected = true;
    }
    
    public static function getName(){
        Browser::detect();
        return Browser::$name;
    }
    public static function getVersion(){
        Browser::detect();
        return Browser::$version;
    }
    public static function getBrowserNames(){
        return Browser::$browsers;
    }
    
}
